<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:a="http://richfaces.org/a4j"
    template="/layout/admin_template.xhtml">

    <ui:define name="body">
    	<h:form>
    		<rich:panel>
    			<f:facet name="header"></f:facet>
	    		<h:commandButton value="#{messages.back_msg}" action="application" immediate="true"/>
	    		<rich:spacer width="10" />
	    		<h:commandButton value="#{messages.save_msg}" action="#{kApplicationManager.save()}" />
	    		<br />
	    		<table>
	    			<tr>
	    				<td>
				    		<ui:include src="/pages/in/k_translate.xhtml" >
				    			<ui:param name="item" value="#{kApplicationManager.application}" />
				    		</ui:include>
	    				</td>
	    			</tr>
	    		</table>
    		</rich:panel>
    	</h:form>
    	<br />
   		<s:fragment id="img_id" rendered="#{kApplicationManager.application.id gt 0}">
	   		<rich:panel>
	  			<f:facet name="header">
					<h:outputText value="#{messages.upload_images_msg}" />
				</f:facet>
			   	<h:form>
			   		<a:outputPanel id="images_id">
			    		<rich:fileUpload id="upload_id"
			    			autoclear="true"
			    			noDuplicate="true"
			    			sizeErrorLabel="TOO BIG"
			    			acceptedTypes="PNG,JPG" 
			    			listHeight="50"
			    			fileUploadListener="#{kApplicationManager.processUpload}" >
			    			<a:support event="onuploadcomplete" action="#{kApplicationManager.loadImages()}" reRender="images_id" />
			    		</rich:fileUpload>
			    		<br />
			    		<br />
			    		<a:outputPanel id="dt_id">
				   			<rich:dataTable id="img_table" value="#{kApplicationManager.images}" var="img">
				   				<rich:column>
				   					<f:facet name="header">
				   						<h:outputText value="#{messages.img_msg}" />
				   					</f:facet>
				   					<a href="/#{kInitParam.imgPath}/app_#{img.applicationId}/#{img.name}" target="blank_">
				  						<img src="/#{kInitParam.imgPath}/app_#{img.applicationId}/#{img.name}" width="50" height="50"/>
						   			</a>
				   				</rich:column>
				   				<rich:column>
				   					<f:facet name="header">
				   						<h:outputText value="#{messages.name_msg}" />
				   					</f:facet>
				  						<h:outputText value="#{img.name}" />
				   				</rich:column>
				   				<rich:column>
				   					<f:facet name="header">
				   						<h:outputText value="#{messages.main_msg}" />
				   					</f:facet>
				   					<table align="center">
				   						<tr>
				   							<td>
						  						<a:commandLink action="#{kApplicationManager.mainImg(img)}" reRender="images_id" immediate="true">
							   						<h:graphicImage value="/img/#{img.main?'star':'star-empty'}.png" 
							   							title="#{messages.main_msg}" alt="#{messages.main_msg}" />
												</a:commandLink>
				   							</td>
				   						</tr>
				   					</table>
				   				</rich:column>
				   				<rich:column id="uc_id">
				   					<f:facet name="header">
				   						<h:outputText value="#{messages.upload_thumb_msg}" />
				   					</f:facet>
				   					<a:region id="tc_id">
					   					<s:fragment rendered="#{empty img.thumb}">
						   					<rich:fileUpload 
								    			autoclear="true"
								    			noDuplicate="true"
								    			sizeErrorLabel="TOO BIG"
								    			acceptedTypes="PNG,JPG" 
								    			listHeight="50"
								    			fileUploadListener="#{kApplicationManager.uploadThumb}" >
								    			<f:attribute name="imageId" value="#{img.id}"/>
								    			<a:support event="onuploadcomplete" action="#{kApplicationManager.loadImages()}" reRender="images_id" />
								    		</rich:fileUpload>
					   					</s:fragment>
					   					<s:fragment rendered="#{not empty img.thumb}">
					   						<a href="/#{kInitParam.imgPath}/app_#{img.applicationId}/#{img.thumb}" target="blank_">
						  						<img src="/#{kInitParam.imgPath}/app_#{img.applicationId}/#{img.thumb}" width="50" height="50"/>
								   			</a>
					   						<h:outputText value="#{img.thumb}" />
						   					<a:commandLink action="#{kApplicationManager.deleteThumb(img)}"
						   						reRender="images_id" immediate="true">
							   					<h:graphicImage value="/img/cross.png" title="#{messages.delete_msg}" />
						    				</a:commandLink>
					   					</s:fragment>
				   					</a:region>
				   				</rich:column>
				   				<rich:column>
				   					<f:facet name="header">
				   						<h:outputText value="#{messages.do_msg}" />
				   					</f:facet>
				   					<h:panelGroup>
					   					<a:commandLink action="#{kApplicationManager.deleteImg(img)}"
					   						reRender="images_id" immediate="true">
					   						<h:graphicImage value="/img/cross.png" title="#{messages.delete_msg}" />
   										</a:commandLink>
				   					</h:panelGroup>
				   				</rich:column>
				   				<f:facet name="footer">
				   					<rich:datascroller renderIfSinglePage="false"/>
				   				</f:facet>
				   			</rich:dataTable>
			    		</a:outputPanel>
			   		</a:outputPanel>
			   	</h:form>
			</rich:panel>
   		</s:fragment>
    </ui:define>
</ui:composition>
